// 负责跳转页面的事件
export default {
	goBack(delta = 1) {
		uni.navigateBack({
			delta
		})
	},
	goTg() {
		this.navTo('/pages/40mySub/addMarket/addMarket');
	},
	jumpUrl(redirect) {
		uni.navigateTo({
			url: redirect,
			fail: (e) => {
				if (e.errMsg.indexOf("tabbar") != -1) {
					uni.reLaunch({
						url: redirect
					})
				}
			},
		});
	},
	// 跳转客服
	goKf() {
		getApp().globalData.VuePrototype.$window.location.href = 'https://work.weixin.qq.com/kfid/kfce44f8ceaedd0f8de';
	},
	// 跳转当前的URl
	goNav(url) {
		if (getApp().globalData.VuePrototype.$util.isIos()) {
			uni.redirectTo({
				url: url,
			});
		} else {
			uni.navigateTo({
				url: url,
			});
		}
	},
	navTo(url) {
		uni.navigateTo({
			url: url,
		});
	},
	redirectTo(url) {
		uni.redirectTo({
			url: url,
		});
	},
	// 跳转当前的URl
	gotoWebView(src, title) {
		uni.navigateTo({
			url: `/pages/_common/webView/webView?src=${src}&title=${title}`
		});
	},

	// 跳转当前的URl
	gotoHerf(herf) {
		getApp().globalData.VuePrototype.$window.location.href = herf;
	},
	// 跳转登陆页面
	goLogin(redirect) {
		if (redirect) {
			if (!redirect.startsWith('/')) {
				redirect = '/' + redirect;
			}
			redirect = encodeURIComponent(redirect);
		}

		uni.navigateTo({
			url: `/pages/_common/login/login?redirect=${redirect}`
		});
	},
	// 回活动首页
	goLoginHome() {
		const fromUserGUID = getApp().globalData.VuePrototype.$store.state.vuex_fromUserGUID;
		getApp().globalData.VuePrototype.$storage.removeAppUserInfo();
		getApp().globalData.VuePrototype.$storage.clear();

		if (fromUserGUID) {
			this.setFromUserGUID(fromUserGUID);
		}

		const url = `/pages/10home/home`;
		uni.reLaunch({
			url: url
		})
	},

	// 回活动首页
	goHome(activeName) {
		const url = `/pages/10home/home`;
		if (activeName) {
			uni.reLaunch({
				url: url
			})
		} else {
			let routes = getCurrentPages();
			let lastPage = routes.length >= 2 ? routes[routes.length - 2].route : ''; // 页面栈中的最后一个项为当前页面，route属性为页面路径
			if (lastPage === 'pages/10home/home') {
				uni.navigateBack()
			} else {
				uni.switchTab({
					url: url
				})
			}
		}
	},
	/**/
	gotoSelectDemo(inputData) {
		getApp().globalData.selectDemo = inputData;
		uni.navigateTo({
			url: '/pages/_common/selectDemo/selectDemo'
		});
	},
	// 跳转文件查看页面
	jumpFile(src, title) {
		let url = `/pages/_common/webPage/webPage?url=https://pic.cwyyt.cn/preview?src=${src}&title=${title}`;
		uni.navigateTo({
			url,
		});
	},
	// 跳转公共组件导航页面
	goNavComp(name, title, initData) {
		let navCompData = {
			name: name, // 组件名称
			title: title, // 页面名称
			initData: initData // 初始化数据
		};
		Object.assign(getApp().globalData.commonPageData.navComponent, navCompData);
		this.goNav('/pages/_common/navComponent/navComponent');
	}
}